<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Account_settings extends MY_Controller {

    //put your code here


    function account_settings() {
        parent :: __construct();
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->commoncall->check_admin_login();
    }

    function index() {
          $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_password_change');
        
    }

    function pass_change() {

        if ($this->input->post('verify')) {
            $this->form_validation->set_rules('oldPass', 'oldPass', 'required|xss_clean');
            $this->form_validation->set_rules('newPass', 'newPass', 'required|xss_clean ');
            $this->form_validation->set_rules('repeatPass', 'repeatPass', 'required|xss_clean|matches[newPass]');
            if ($this->form_validation->run()) {
                if ($this->session->userdata('sess_admin_password') == trim($this->input->post('oldPass'))) {
                    $data = array('password' => $this->input->post('newPass'));
                    $this->db->where('name', $this->session->userdata('sess_admin_name'));
                    $this->db->update('admin_user', $data);
                    $this->session->set_flashdata('message', 'Password Changed Sucessfully Login with new Password....');
                    redirect('admin/account_settings');
                    
                                                       
                } else {
                    $this->session->set_flashdata('message', 'Old password does not match or empty');
                    redirect('admin/account_settings');
                }
            } else {
                $this->session->set_flashdata('message', 'Error!Fields are empty or repeat password mismatch ');
                redirect('admin/account_settings');
            }
        }
         
    }

}

?>
